package com.lwj.project1.PersonActivity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.ListView;

import com.lwj.project1.R;
import com.lwj.project1.RecommendPageFragments.MyGameAdapter;
import com.lwj.project1.databaseHelper.MySqliteOpenHelper;
import com.lwj.project1.entity.Game;
import com.lwj.project1.entity.GameCard;
import com.lwj.project1.entity.GameCategory;

import java.util.ArrayList;
import java.util.List;

public class LikeActivity extends AppCompatActivity {

    private ListView listView;
    private List<GameCard> gameCards;
    private MySqliteOpenHelper mySqliteOpenHelper;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_like);

        listView = findViewById(R.id.like_listView);
        gameCards = new ArrayList<>();
        mySqliteOpenHelper = new MySqliteOpenHelper(getApplicationContext());
        SharedPreferences sharedPreferences = getSharedPreferences("project_content",MODE_PRIVATE);
        String username = sharedPreferences.getString("username","");

        List<Game> likes = mySqliteOpenHelper.findPersonLikeGames(username);
        if (likes == null || likes.size() < 0){
            GameCard gameCard = new GameCard("","您还没有添加桌游哦~","您还没有添加桌游哦~");
            gameCards.add(gameCard);
            MyGameAdapter adapter = new MyGameAdapter(getApplicationContext(),gameCards);
            listView.setAdapter(adapter);
            return;
        }
        for (int i = 0;i < likes.size();i++){
            GameCategory gameCategory = mySqliteOpenHelper.findGameCategoryById(likes.get(i).getGameCategoryId());
            GameCard gameCard = new GameCard(gameCategory.getGameCategoryImg(),gameCategory.getGameCategoryName(),likes.get(i).getGameDescription());
            gameCards.add(gameCard);
        }
        MyGameAdapter adapter = new MyGameAdapter(getApplicationContext(),gameCards);
        listView.setAdapter(adapter);
    }
}